//
//  ExitMenu.h
//  CExitMenu: Main class of the game
//
//  Created by Enric Vergara on 20.10.12. 
//  Copyright OWLAB 2010. All rights reserved.
// Import the interfaces

#import "ExitMenu.h"
#import "MainMenu.h"
#import "SoundManager.h"


// CExitMenu implementation
@implementation CExitMenu



// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if ((self = [super init]))
    {
        CGSize screenSize = [[CCDirector sharedDirector] winSize];
        CGPoint center = CGPointMake(screenSize.width/2, screenSize.height/2);
        //Definim el tapete del joc
        m_Background = [CCSprite spriteWithFile:@"menuExit_background.JPG"]; 
        m_Background.position =center;
        [self addChild:m_Background];

       [CCMenuItemFont setFontName:@"Arial"];
        [CCMenuItemFont setFontSize:40];
        m_Button_BackToMenu_Yes = [CCMenuItemFont itemFromString:@"Yes" target:self selector:@selector(menuBackToMenu_Yes:)];
		m_Button_BackToMenu_Yes.position =  CGPointMake(- 50, -50);
        
        m_Button_BackToMenu_No = [CCMenuItemFont itemFromString:@"No" target:self selector:@selector(menuBackToMenu_No:)];
        m_Button_BackToMenu_No.position =  CGPointMake(50, -50);

        m_Button_Menu = [CCMenuItemFont itemFromString:NSLocalizedString(@"Exit?", @"") 
                                                target:self selector:@selector(menuBackToMenu_Exit:)];
        m_Button_Menu.position =  CGPointMake(screenSize.width/2-100, screenSize.height/2-100);

        
        
        // create the menu using the items
        m_Menu = [CCMenu menuWithItems:m_Button_BackToMenu_Yes, m_Button_BackToMenu_No, m_Button_Menu, nil];
        m_Menu.position = center;
        [self addChild:m_Menu];
        m_Menu.visible = true;

        //label indicant Do you want really exit?
        m_sExitLabel = [CCLabel labelWithString: NSLocalizedString(@"Exit??", @"") fontName:@"Arial" fontSize:40];
        [m_sExitLabel setColor:ccc3(0,0,0)];
        [m_sExitLabel setPosition:CGPointMake(center.x,center.y + 50)];
        [self addChild: m_sExitLabel];
        
        
        //fer desapareixer el menu de "vols sortir?"
        m_Button_Menu.visible = true;
        
        m_Button_BackToMenu_Yes.visible =
        m_Button_BackToMenu_No.visible  =
        m_sExitLabel.visible            =
        m_Background.visible            = false;
        
		// must be enabled if you want to receive touch events!
		self.isTouchEnabled = YES;
        
        
	}
	return self;
}


-(void) ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{

}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

-(void) menuBackToMenu_Yes: (id) sender
{
    [[SoundManager sharedInstance] stopMusic];
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_BACK];
    //change scene
    [[CCDirector sharedDirector] replaceScene:[CMainMenu scene]];
}

-(void) menuBackToMenu_No: (id) sender
{
    [[SoundManager sharedInstance] stopMusic];
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
    
    //fer desapareixer el menu de "vols sortir?"
    m_Button_Menu.visible = true;
    
    m_Button_BackToMenu_Yes.visible =
    m_Button_BackToMenu_No.visible  =
    m_sExitLabel.visible            =
    m_Background.visible            = false;
}

-(void) menuBackToMenu_Exit: (id) sender
{
    [[SoundManager sharedInstance] playMusic:SOUND_SECOND_MENU_LOOP loop:true];
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
    
    //fer apareixer el menu de "vols sortir?"
    m_Button_Menu.visible = false;
    
    m_Button_BackToMenu_Yes.visible =
    m_Button_BackToMenu_No.visible  =
    m_sExitLabel.visible            =
    m_Background.visible            = true;
    
}


// on "dealloc" you need to release all your retained objects
-(void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
